<?php
$id = $_GET['did'] ?? 1;
$tpl = $_GET['tid'] ?? 1;
// 语言切换处理
$availableLangs = ['zh', 'en', 'ja', 'ko']; // 支持的语言
$lang = 'zh'; // 默认语言

// 检查用户选择的语言
if (isset($_GET['lang']) && in_array($_GET['lang'], $availableLangs)) {
    $lang = $_GET['lang'];
    // 存储语言偏好到会话
    session_start();
    $_SESSION['lang'] = $lang;
} elseif (isset($_SESSION['lang']) && in_array($_SESSION['lang'], $availableLangs)) {
    // 使用会话中保存的语言偏好
    $lang = $_SESSION['lang'];
}

$langList = [
    'zh' => [
        'forum_name' => '论坛版块',
        'forum_count' => '帖子数',
        'forum_lat_post' => '最后发帖',
        'download_os' => '操作系统',
        'download_processor' => '处理器',
        'download_memory' => '内存',
        'download_graphics' => '显卡',
        'download_storage' => '存储空间',
        'download_internet' => '网络',
        'download_notice' => '注意事项'
     ],
     'en' => [
         'forum_name' => 'Forum Sections',
            'forum_count' => 'Threads',
            'forum_lat_post' => 'Last Post',
            'download_os' => 'Operating System',
            'download_processor' => 'Processor',
            'download_memory' => 'Memory',
            'download_graphics' => 'Graphics',
            'download_storage' => 'Storage',
            'download_internet' => 'Internet',
            'download_notice' => 'Important Notes'
     ],
     'ja' => ['forum_name' => 'フォーラムセクション',
'forum_count' => 'スレッド数',
'forum_lat_post' => '最終投稿',
'download_os' => 'オペレーティングシステム',
'download_processor' => 'プロセッサ',
'download_memory' => 'メモリ',
'download_graphics' => 'グラフィックス',
'download_storage' => 'ストレージ',
'download_internet' => 'インターネット',
'download_notice' => '重要な注意事項'],
    'ko' => ['forum_name' => '포럼 섹션',
'forum_count' => '스레드 수',
'forum_lat_post' => '마지막 게시물',
'download_os' => '운영 체제',
'download_processor' => '프로세서',
'download_memory' => '메모리',
'download_graphics' => '그래픽',
'download_storage' => '저장 공간',
'download_internet' => '인터넷',
'download_notice' => '중요 사항'],
'fr' => ['forum_name' => 'Sections du forum',
'forum_count' => 'Discussions',
'forum_lat_post' => 'Dernier message',
'download_os' => 'Système d\'exploitation',
'download_processor' => 'Processeur',
'download_memory' => 'Mémoire',
'download_graphics' => 'Carte graphique',
'download_storage' => 'Stockage',
'download_internet' => 'Internet',
'download_notice' => 'Notes importantes']
    
];
function _t($key){
    global $langList,$lang;
    $langItem = $langList[$lang] ?? $langList['zh'];
    if(isset($langItem[$key])){
        return $langItem[$key];
    }
    return $key;
}

include 'data/'.$id.'.php';
// 获取当前语言的翻译数据
$t = $translations[$lang];
if(!isset($t['preRegister'])){
    $t['preRegister'] = [
        'title' => '预注册现在开启',
        'subtitle' => '立即预注册《我的完美世界》，抢先获得游戏测试资格和专属豪华礼包，开启你的奇幻之旅',
        'form' => [
            'name' => '姓名',
            'phone' => '手机号码',
            'email' => '电子邮箱',
            'placeholderName' => '请输入您的姓名',
            'placeholderPhone' => '请输入您的手机号码',
            'placeholderEmail' => '请输入您的电子邮箱',
            'agreement' => '我已阅读并同意《用户服务协议》和《隐私政策》，并愿意接收《我的完美世界》的最新资讯和活动信息',
            'submit' => '立即预注册'
        ],
        'stats' => [
            ['value' => '100万+', 'label' => '预约人数'],
            ['value' => '50+', 'label' => '游戏场景'],
            ['value' => '10+', 'label' => '特色系统'],
            ['value' => '5', 'label' => '职业选择']
        ],
        'gift' => '预注册专属礼包：稀有坐骑+限定外观+新手套装' // 新增礼包信息
    ];
}
if(!isset($t['download'])){
    $t['download'] = [
        'pretitle' => '立即下载',
        'title' => '加入战场',
        'subtitle' => '下载王者荣耀，随时随地开启5v5对战',
        'clients' => [
            [
                'os' => 'Android',
                'size' => '约 2.5 GB',
                'icon' => 'fa-android',
                'downloadLink' => '#',
                'buttonText' => '下载APK',
                'secondButton' => [
                    'text' => '应用商店',
                    'link' => '#'
                ]
            ],
            [
                'os' => 'iOS',
                'size' => '约 2.8 GB',
                'icon' => 'fa-apple',
                'downloadLink' => '#',
                'buttonText' => 'App Store',
            ]
        ],
        'notes' => [
            '首次运行需要下载额外资源',
            '建议在WiFi环境下下载',
            '请确保设备有足够存储空间'
        ],
        'requirements' => [
            'minimum' => [
                'title' => '最低配置',
                'os' => 'Android 5.0 / iOS 9.0',
                'processor' => '四核处理器',
                'memory' => '3 GB RAM',
                'storage' => '3 GB 可用空间',
                'internet' => '稳定网络连接'
            ],
            'recommended' => [
                'title' => '推荐配置',
                'os' => 'Android 8.0 / iOS 12.0',
                'processor' => '八核处理器',
                'memory' => '6 GB RAM',
                'storage' => '6 GB 可用空间',
                'internet' => '高速网络连接'
            ]
        ]
    ];
}
include 'tpl/'.$tpl.'/index.php';